Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc dependency library from the forward link #501

Closed
wants to merge 1 commit into from
Closed

gcc dependency library from the forward link #501

wants to merge 1 commit into from

Conversation

KangLin
Copy link

@KangLin KangLin commented Oct 20, 2015

gcc dependency library from the forward link。so gdi32 put back。

@jay
Copy link
Member

jay commented Oct 20, 2015

Can you tell us what error you are seeing without this fix? The order should be (and is currently) -lssl -lcrypto -lgdi32 <others> because OpenSSL needs gdi32, but as far as I know none of the other libraries need it so I don't know why we would change it to -lssl -lcrypto <others> -lgdi32

@KangLin
Copy link
Author

KangLin commented Oct 20, 2015

on my environment generate :
-lssl -lcrypto -lgdi32 -lssl -lcrypto
It seems to be reading the script twice openssl.
So in order to be compatible, change the order.

@MoSal
Copy link
Contributor

MoSal commented Oct 20, 2015

This could happen indeed with librtmp-enabled builds.

@KangLin
Copy link
Author

KangLin commented Oct 20, 2015

Yes.
Because other libraries may depend on gdi32, so change the order.

@jay
Copy link
Member

jay commented Oct 21, 2015

How are you building curl? The only way I can see that happening is if you have a pkgconfig file for openssl that is specifying ssl and crypto static without specifying gdi32 and you are doing a static build of libcurl.

It appears that it's not easy to build libcurl static with a static pkg-config OpenSSL, at least in the case of mingw. To remedy that we can support the PKG_CONFIG="pkg-config --static" workaround. However even with --static gdi32 may not be added in the right order. I sent an e-mail to OpenSSL earlier this evening asking about that.

What wouldn't hurt on our end is to move the gdi32 check to the beginning of the ssl block before anything else (in other words gdi32 will appear at least once after any ssl libs) and allow PKG_CONFIG to set pkg-config location and options in curl's CURL_CHECK_PKGCONFIG macro to allow the user to specify their own pkg-config and switches.

Please let me know if this works for you however you normally build:
https://github.com/jay/curl/compare/master...jay:fix_static_openssl_mingw?expand=1

@bagder bagder added the build label Oct 21, 2015
@KangLin
Copy link
Author

KangLin commented Oct 22, 2015

Yes. I am doing a static build of libcurl.
I compile the configuration and compilation errors:

Configure:

../configure --enable-static --disable-shared --enable-sse  LDFLAGS="-static" --prefix=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --disable-manual --enable-verbose --with-ssl=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --with-sysroot=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static 

Error:

/bin/sh ../libtool  --tag=CC   --mode=link gcc  -O2 -Wno-system-headers   -static -LD:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib -o curl.exe curl-slist_wc.o curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_strdup.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o  ../lib/libcurl.la  -lssh2 -lssl -lcrypto -lgdi32 -lssl -lcrypto -lwldap32 -lz -lws2_32
libtool: link: gcc -O2 -Wno-system-headers -o curl.exe curl-slist_wc.o curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_strdup.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o  -LD:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib ../lib/.libs/libcurl.a -lssh2 -lgdi32 -lssl -lcrypto -lwldap32 -lz -lws2_32
D:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xf9d): undefined reference to `_imp__GetDeviceCaps@8'
D:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xfcb): undefined reference to `_imp__CreateCompatibleBitmap@12'
D:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xfed): undefined reference to `_imp__GetObjectA@12'
D:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0x10e0): undefined reference to `_imp__GetDIBits@28'
D:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0x1152): undefined reference to `_imp__DeleteObject@4'
collect2.exe: error: ld returned 1 exit status
Makefile:772: recipe for target 'curl.exe' failed
make[2]: *** [curl.exe] Error 1
make[2]: Leaving directory '/d/source/curl/build_windows_mingw/src'
Makefile:651: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/d/source/curl/build_windows_mingw/src'
Makefile:874: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

Use your code (https://github.com/jay/curl/compare/master...jay:fix_static_openssl_mingw?expand=1). It works fine.
Configure1:

../configure --enable-static --disable-shared --enable-sse   LDFLAGS="-static" --prefix=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --disable-manual --enable-verbose --with-ssl=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --with-sysroot=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static

Configure2:

../configure --enable-static --disable-shared LDFLAGS="-static" PKG_CONFIG="pkg-config --static" --enable-sse  --prefix=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --disable-manual --enable-verbose --with-ssl=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --with-sysroot=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static 

linker output:

/bin/sh ../libtool  --tag=CC   --mode=link gcc  -O2 -Wno-system-headers   -static -LD:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib -o curl.exe curl-slist_wc.o curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_strdup.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o  ../lib/libcurl.la  -lssh2 -lssl -lcrypto -lssl -lcrypto -lgdi32 -lwldap32 -lz -lws2_32
libtool: link: gcc -O2 -Wno-system-headers -o curl.exe curl-slist_wc.o curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_strdup.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o  -LD:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib ../lib/.libs/libcurl.a -lssh2 -lssl -lcrypto -lgdi32 -lwldap32 -lz -lws2_32

While your code to work properly, but I still think this place needs to change the order. Because gdi32 is the basic library, which does not depend on other libraries, other libraries(except openssl) may be directly or indirectly dependent on it. And gcc forward link libraries. So there remains a need to change the order.

@jay
Copy link
Member

jay commented Oct 22, 2015

There's really a broader issue here which is what is our responsibility if a user is making a static libcurl and wants to link static dependencies as well. If the user wants to link static dependency foo, which may depend on bar and baz, how would we know it depends on bar and baz? One can use the pkgconfig --static workaround. Is there a better way to handle this with libtool? I'm sure it does what it can when it sees -static in LDFLAGS.

We are making a best guess for OpenSSL in the case of mingw/msys by including gdi32 in the case of ssl. If any other library is dependent on gdi32 we should address that separately; or not based on what we think about the first issue. In that case I would move the test for gdi32 earlier than I made it now so it would not be specific to ssl. Both of our proposed changes make it so that gdi32 is only added if ssl, so both would be incorrect in the case that gdi32 could be a dependency for other static libraries.

The commit I've proposed addresses what you reported in the least disruptive manner, however I'm open to other ideas.

@KangLin
Copy link
Author

KangLin commented Oct 22, 2015

libcurl is not directly dependent on gdi32, so there isn't need to test gdi32(The library depend on gdi32 to deal with the gdi32).
If you want to test gdi32 in libcurl, then you need to change the order. gcc dependency library forward link。so gdi32 put back。

http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

@bagder
Copy link
Member

bagder commented Oct 22, 2015

Linking statically basically means you need to provide the dependencies manually as they're next to impossible for us to figure out and provide.

jay added a commit that referenced this pull request Oct 23, 2015
- If mingw ssl make sure -lgdi32 comes after ssl libs

- Allow PKG_CONFIG to set pkg-config location and options

Bug: #501
Reported-by: Kang Lin
@jay
Copy link
Member

jay commented Oct 23, 2015

@KangLin I don't see a better idea than what I proposed so I've landed my changes in 72d99f2. That combined with the build method in #503 and you should be good to go.

@jay jay closed this Oct 23, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

None yet

4 participants